<template>
	<view>
		<view class="cu-bar bg-white solid-bottom margin-top">
			<view class="action">
				<text class="cuIcon-title text-orange">{{ task.title }}</text>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom margin-top">
			<view class="action" text-red>填写任务答案</view>
		</view>
		<view class="cu-bar bg-white solid-bottom margin-top">
			<view class="action" text-red>
				<van-cell-group>
					<van-field :value="formData.content" @input="input($event,'content')" placeholder="请输入任务答案" required
						clearable />
				</van-cell-group>
			</view>
		</view>
		<van-divider contentPosition="center" customStyle="color: #1989fa; border-color: #1989fa; font-size: 18px;">
			图片上传 (仅限一张)
		</van-divider>
		<view class="cu-bar bg-white solid-bottom margin-top">
			<view class="action" text-red>
				<van-cell-group>
					<tm-upload @getPicUrl="getUrl"></tm-upload>
				</van-cell-group>
			</view>
		</view>
		<van-divider contentPosition="center" customStyle="color: #1989fa; border-color: #1989fa; font-size: 18px;">
			视频上传 (仅限一个)
		</van-divider>
		<view class="cu-bar bg-white solid-bottom margin-top">
			<view class="action" text-red>
				<van-cell-group>
					<tm-upload-video @getVideoUrl="getVideoUrl"></tm-upload-video>
				</van-cell-group>
			</view>
		</view>
		<van-goods-action>
			<van-goods-action-button text="提交" @click="submit()" />
		</van-goods-action>
		<!-- 		<van-cell-group>
			<van-uploader :file-list="imageValue" max-count="1" :deletable="true" :after-read="afterRead" />
		</van-cell-group> -->
		<!-- 	<van-divider
		  contentPosition="center"
		  customStyle="color: #1989fa; border-color: #1989fa; font-size: 18px;"
		>
		  视频上传
		</van-divider>
		<van-cell-group>
			<van-uploader :file-list="videoValue" max-count="1" accept="video/*" :after-read="afterVideoRead" />
		</van-cell-group> -->
	</view>
</template>

<script>
	import tmUpload from '@/components/tm-upload/tm-upload.vue'
	import tmUploadVideo from '@/components/tm-upload-video/tm-upload-video.vue'
	export default {
		components: {
			tmUpload,
			tmUploadVideo
		},
		data() {
			return {
				formData: {
					// taskId: this.taskId,
					taskId:"",
					stuId: '',
					content: '',
					picUrl: '',
					videoUrl: '',
					wordUrl: '',
					status: 1
				},
				task: {
				}
			}
		},
		onLoad: function(option) {
			this.formData.taskId = option.taskId;
			this.getData()
		},
		methods: {
			input(event,name) {
				let {
					detail
				} = event;
				this.formData[name] = detail;
			},
			getData() {
				uni.request({
					url: 'http://localhost:8082/task_admin/task/getTask?taskId=' + this.formData.taskId,
					method: "GET",
					success: (res) => {
						console.log("res.data",res.data)
						if (res.data.code == 200) {
							this.task = res.data.data
							console.log("task {} ",this.task)
						}
					}
				});
			},
			// 提交
			submit() {
				this.formData.stuId = uni.getStorageSync('stuId');
					uni.request({
						url: 'http://localhost:8082/task_admin/task-exec/add',
						data: this.formData,
						dataType:"json",
						method:"POST",
						success: (res) => {
							console.log(res)
							if (res.data.code == 200) {
								uni.navigateTo({
									url: '/pages/student/task-list'
								});
							}
						}
					});
			},
			getUrl(fileArray) {
				console.log("触发父组件" + fileArray)
				this.formData.picUrl = fileArray
			},
			getVideoUrl(file) {
				console.log("触发父组件" + file)
				this.formData.videoUrl = file
			}
		}
	}
</script>

<style>
</style>
